package leetcode;

public class LC13 {
    public static void main(String[] args) {

    }
    public int maxSubArray(int[] nums) {
        int[] max = new int[nums.length];
        max[0] = nums[0];
        for(int i = 1; i< nums.length; i++){
            max[i] = Math.max(max[i-1]+nums[i], nums[i]);
        }
        int ans = max[0];
        for(int i = 1; i< nums.length; i++){
            ans = Math.max(ans,max[i]);
        }
        return ans;
    }
}
